package threadUtils;

import java.util.concurrent.CountDownLatch;

public abstract class BaseCountDown implements Runnable {

    private CountDownLatch countDownLatch;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private boolean isSuccess;

    public BaseCountDown(String serviceName, CountDownLatch latch) {
        this.name = serviceName;
        this.countDownLatch = latch;
        this.isSuccess = false;
    }

    @Override
    public void run() {
        try {
            read();
            isSuccess = true;
        } catch (Exception e) {
            e.printStackTrace();
            isSuccess = false;
        } finally {
            if (countDownLatch != null) {
                countDownLatch.countDown();
            }
        }
    }

    public abstract void read();

    public boolean isSuccess() {
        return isSuccess;
    }

}
